//
//  LCInviteExplainView.m
//  lechuang
//
//  Created by Mr_hi on 2023/6/19.
//  Copyright © 2023 Mooyi. All rights reserved.
//

#import "LCInviteExplainView.h"


@interface LCInviteExplainView ()

@property (weak, nonatomic) IBOutlet UIView *alertView;

@property (assign, nonatomic) CGFloat alertW;

@property (assign, nonatomic) CGFloat alertH;

@end

@implementation LCInviteExplainView

-(instancetype)initForNib {
    self = [[NSBundle mainBundle] loadNibNamed:NSStringFromClass(self.class) owner:nil options:nil][0];
    [self configUI];
    return self;
}

-(void)configUI {
    self.frame=CGRectMake(0, 0, ScreenW, ScreenH);
    self.alpha = 0;
    
    self.alertW = ScreenW-34;
    NSString * msgText = @"1、可以直接复制邀请码给好友让好友下载APP并注册登录\n\n2、可以复制下载二维码和邀请链接让好友下载APP并注册登录\n\n3、可以好友可以通过您的邀请码或二维码注册会员并下载APP后，他将永久成为您的下级会员，未来他产生的订单佣金你都有奖励，会自动计入您的账户中！";
    
    self.alertH = 49 + 19 + [LCFunction lc_stringSizeWithFont:[UIFont systemFontOfSize:12] str:msgText maxWidth:self.alertW-28 maxHeight:CGFLOAT_MAX].height;
    self.alertView.transform = CGAffineTransformMakeScale(1.0/self.alertW, 1.0/self.alertH);
    
    [self whenTapped:^{
        [self dismiss];
    }];
    [self setNeedsLayout];
    [[UIApplication sharedApplication].keyWindow bringSubviewToFront:self];
}

-(void)show {
    [[UIApplication sharedApplication].keyWindow addSubview:self];
    [UIView animateWithDuration:0.25f animations:^{
        self.alertView.transform = CGAffineTransformMakeScale(1, 1);
        self.alpha = 1;
        [self layoutIfNeeded];
    }];
}

-(void)dismiss {
    [UIView animateWithDuration:0.25f animations:^{
        self.alertView.transform = CGAffineTransformMakeScale(1.0/self.alertW, 1.0/self.alertW);
        self.alpha = 1;
        [self layoutIfNeeded];
    } completion:^(BOOL finished) {
        [self removeFromSuperview];
    }];
}

- (IBAction)cancelBtnAction:(UIButton *)sender {
    [self dismiss];
}

@end
